import type { ResponseData } from '@/utils/types.d';
import { SUCCESS_CODE } from '@/utils/types.d';
import request from '@/utils/request';
import type { ParkingRecordTableListItem } from './types.d';

export async function queryParkingRecords(
  params: any,
  sort: any,
): Promise<{
  success: boolean;
  total: number;
  data: ParkingRecordTableListItem[];
}> {
  const res: ResponseData<{
    total: number;
    data: ParkingRecordTableListItem[];
  }> = await request('/api/parking-record/v1.0.0/records', {
    method: 'GET',
    params: {
      data: params,
      sort,
    },
  });
  if (res?.code === SUCCESS_CODE)
    return { success: true, total: res.data.total, data: res.data.data };
  return { success: false, total: 0, data: [] };
}
// /api/parking-record/v1.0.0/record/{id}

export async function getParkingRecord(
  recordId: string,
  more: boolean = false,
): Promise<{
  success: boolean;
  message: string;
  data: ParkingRecordTableListItem;
}> {
  const res: ResponseData<ParkingRecordTableListItem> = await request(
    `/api/parking-record/v1.0.0/record/${recordId}`,
    {
      params: {
        more,
      },
    },
  );
  if (res?.code === SUCCESS_CODE) return { success: true, message: '获取成功', data: res.data };
  return { success: false, message: res?.message || '获取失败', data: res.data };
}
